import request from "../axios/request";


function register(data = {}, captcha) {
    return new Promise((resolve, reject) => {
        request('post', '/user/register?captcha=' + captcha, data)
            .then(res => {
                resolve(res)
            }, error => {
                console.log(error)
                reject(error)
            })
    })
}

function login(data = {}){
    return new Promise((resolve, reject) => {
        request('post', 'user/login', data)
            .then(res => {
                resolve(res)
            }, err => {
                reject(err)
            })
    })
}

function addUser(data = {}) {
    return new Promise((resolve, reject) => {
        request('post', '/user/add', data)
            .then(res => {
                resolve(res)
            }, err => {
                reject(err)
            })
    })
}


function getManagerUserInfoWithConditions() {
    return new Promise((resolve, reject) => {
        request('get', '/user/getManagerUserInfoWithConditions', {
            districtId: '',
            orgNameKeyWord: '',
            realName: '',
            username: '',
            role: '',
            orgType: ''
        })
            .then(res => {
                resolve(res)
            }, err => {
                reject(err)
            })
    })
}

function changePassword(userId, data) {
    return new Promise((resolve, reject) => {
        request('post', '/user/modifyPassword?userId=' + userId, data)
            .then(res => {
                resolve(res)
            }, err => {
                reject(err)
            })
    })
}

/**
 * 获取用户的扩展信息
 * @param userId 用户id
 * @returns {Promise<unknown>}
 */
function getUserExtendMsg(userId) {
    return new Promise((resolve, reject) => {
        request("get", "/userExtendMsg/getUserExtendMsg", {
            userId,
        }).then(resp => {
            resolve(resp);
        }, err => {
            reject(err);
        })
    })
}

export {
    register,
    login,
    getManagerUserInfoWithConditions,
    addUser,
    changePassword,
    getUserExtendMsg,
}